import 'package:baselib/util/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/util/colours.dart';
import 'package:super_tooltip/super_tooltip.dart';

class ContanctPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new ContanctPageState();
  }
}



class ContanctPageState extends State<ContanctPage>{

  GlobalKey _key1 = GlobalKey();
  SuperTooltip tooltip;
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return  MouseRegion (
      onEnter: (event){
        showContactTip(context);
      },
      onExit: (event){
        if (tooltip != null && tooltip.isOpen) {
          tooltip.close();
        }
      },
      onHover: (event){
        // print("移动");
      },
      child: Container(
        width: 80,
        color: ColourRes.app_265385,
        child: Column(
          children: [
            SizedBox(
              height: 5,
            ),
            Image.asset(
              CommonUtils.getImgPath("kefu.png"),
              width: 24,
            ),
            SizedBox(
              height: 10,
            ),
            Text(
              "联系客服",
              style: TextStyle(color: Colors.white),
            ),
            SizedBox(
              height: 5,
            ),
          ],
        ),
      ),
    );
  }

  void showContactTip(BuildContext context){
    // We create the tooltip on the first use
    if (tooltip != null && tooltip.isOpen) {
      tooltip.close();
      return;
    }

    var renderBox = context.findRenderObject() as RenderBox;
    final overlay = Overlay.of(context).context.findRenderObject() as RenderBox;

    var targetGlobalCenter = renderBox
        .localToGlobal(renderBox.size.center(Offset.zero), ancestor: overlay);


     tooltip = SuperTooltip(
       hasShadow: false,
       containsBackgroundOverlay:false,
      popupDirection: TooltipDirection.left,
      touchThrougArea: new Rect.fromLTWH(targetGlobalCenter.dx,
          targetGlobalCenter.dy, 200.0, 160.0),
      content: new Container(

          child: Text(
            "服务热线0111111 ",
            softWrap: true,
          )),
    );

    tooltip.show(context);

  }
}